﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    internal class CurveState
    {
        public AnimationSelection animationSelection;
        public Color color;
        public bool even;
        public Vector2 guiPosition;
        private bool m_Animated;
        private AnimationClipCurveData m_CurveData;

        public CurveState(AnimationClipCurveData curveData)
        {
            this.m_CurveData = curveData;
        }

        public int GetGroupID()
        {
            return CurveUtility.GetCurveGroupID(this.clip, this.curveData);
        }

        public int GetID()
        {
            return CurveUtility.GetCurveID(this.clip, this.curveData);
        }

        public float GetSampledOrCurveValue(float time)
        {
            float positiveInfinity;
            if (this.animated)
            {
                CurveRenderer curveRenderer = CurveUtility.GetCurveRenderer(this.clip, this.curveData);
                if (curveRenderer == null)
                {
                    Debug.LogError("The renderer is null!");
                }
                return curveRenderer.EvaluateCurveSlow(time);
            }
            if (!CurveUtility.GetFloatValue(this.animationSelection.animatedObject, this.curveData.path, this.curveData.type, this.curveData.propertyName, out positiveInfinity))
            {
                Debug.LogError("Object property value could not be sampled for " + this.curveData.path + "/" + this.curveData.propertyName);
                positiveInfinity = float.PositiveInfinity;
            }
            return positiveInfinity;
        }

        public void SaveCurve(AnimationCurve curve)
        {
            AnimationUtility.SetEditorCurve(this.clip, this.curveData.path, this.curveData.type, this.curveData.propertyName, curve);
            if (this.curveData.propertyName.StartsWith("localEulerAngles."))
            {
                ((EulerCurveRenderer) CurveUtility.GetCurveRenderer(this.clip, this.m_CurveData)).SetQuaternionsDirty();
            }
        }

        public bool animated
        {
            get
            {
                return this.m_Animated;
            }
            set
            {
                this.m_Animated = value;
            }
        }

        public AnimationClip clip
        {
            get
            {
                return this.animationSelection.clip;
            }
        }

        public AnimationCurve curve
        {
            get
            {
                return CurveUtility.GetCurveRenderer(this.clip, this.m_CurveData).GetCurve();
            }
        }

        public AnimationClipCurveData curveData
        {
            get
            {
                return this.m_CurveData;
            }
            set
            {
                this.m_CurveData = value;
            }
        }
    }
}

